package com.cf.core.model.diagram.background {
	import com.cf.core.model.diagram.config.param;
	import com.cf.core.model.diagram.constants.BackgroundSet;
	import flash.display.DisplayObjectContainer;
	import flash.display.Sprite;
	import com.cf.core.view.MySprite;
	import com.cf.core.model.diagram.background.axis.Label;
	import com.cf.core.Utils.debug;
	import flash.events.Event;
	public class BaseBackground extends BackgroundSet {
		// API parts
		private var G_prop:param;
		//public function set PARAM(_p:param):void { G_prop = _p }
		public function get PARAM():param { return G_prop }
		public function get toWidth():Number { return Math.ceil(G_prop.width - G_padding * 2); }	// width,height we wanted to be
		public function get toHeight():Number {
			var _toh:Number = Math.ceil(G_prop.height - G_padding * 2);
			if (_toh < 0) _toh = (G_padding * 2) + G_prop.cellSize;
			return _toh
		}	// remark realsize will +1, it's border
		private var G_padding:Number;
		public function set padding(_n:Number):void { G_padding = _n }
		public function get padding():Number { return G_padding }
		// End : API parts
		private var G_mask:MySprite;
		public function get MASK():DisplayObjectContainer{return G_mask}
		private var G_graph:Sprite;
		public function get GRAPH():Sprite { return G_graph }
		private var G_ui:Sprite;
		public function get UI():Sprite{return G_ui}
		
		
		public function BaseBackground():void {
			G_mask = new MySprite();
			G_graph = new Sprite();
			G_ui = new Sprite();
			G_graph.mask = this.MASK;
			// this.graph.alpha = .3;
			this.addChild(this.MASK);
			this.addChild(this.GRAPH);
			this.addChild(this.UI);
			G_padding = 20;
			this.addEventListener(Event.ADDED_TO_STAGE, handleScene);
			this.addEventListener(Event.REMOVED_FROM_STAGE, handleScene);
		}//fn
		private function handleScene(e:Event):void {
			switch(e) {
				case Event.ADDED_TO_STAGE:
				
				break;
				case Event.REMOVED_FROM_STAGE:
					RELEASE();
				break; 
			}
		}//fn
		
		public function drawChart():void {
			// please override at child to modify the detail.
			debug.msg("CHECK ME FIRST");
		}//fn
		
		override public function draw():void {
			this.MASK.x = G_padding;
			this.MASK.y = G_padding;
			G_mask.reset();
			// G_mask.Rect(0, 0, (this.toWidth+1-G_padding * 2), (this.toHeight+1-G_padding * 2));	// visible area.
			G_mask.Rect(0, 0, this.toWidth+1, this.toHeight+1);	// visible area.
			this.GRAPH.graphics.clear();	// clear up.
			this.GRAPH.x = G_padding;
			this.GRAPH.y = G_padding;
			this.UI.x = G_padding;
			this.UI.y = G_padding;
			// debug.msg("BaseBackground: width=" + toWidth +" Height=" + toHeight);
		}//fn
		
		override public function setup(_prop:param):void {
			G_prop = _prop;
			// let child to find out it's own value from prop.
		}//fn
		override public function RELEASE(e:*= null):void {
			this.removeChild(this.MASK);
			this.removeChild(this.GRAPH);
		}//fn
		override public function toString():String {
			return "com.cf.core.model.diagram.background.BaseBackground";
		}//fn
	}//class
}//package